package com.lh.springcloud.service;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.stream.annotation.EnableBinding;
import org.springframework.cloud.stream.annotation.StreamListener;
import org.springframework.cloud.stream.messaging.Sink;
import org.springframework.messaging.Message;
import org.springframework.messaging.handler.annotation.SendTo;
import org.springframework.stereotype.Service;

@Service
@EnableBinding(Sink.class)
public class ReceiveMessageListener {

    @Value("${server.port}")
    private String serverPort;

    //  使用@StreamListener注解，指定监听的消息通道为Sink.INPUT
    @StreamListener(Sink.INPUT)
    // 定义一个公共的方法，参数为一个Message对象，泛型为String
    public void input(Message<String> message) {
        //输出生产者消息的内容以及消费者消息的端口号信息
        System.out.println("消费者1号，------->接收到的消息：" + message.getPayload() + "\t port: " + serverPort);
    }

}
